package top.zlcode.api.file;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;
import top.zlcode.api.config.FeignMultipartConfig;
import top.zlcode.api.file.vo.FileDeleteVO;
import top.zlcode.api.file.vo.FileUploadVO;
import top.zlcode.common.core.constants.Constants;
import top.zlcode.common.core.domain.R;

@FeignClient(
        contextId = "RemoteFileService",
        value = Constants.FILE_SERVICE,
        configuration = FeignMultipartConfig.class  // 关联配置类
)
public interface RemoteFileService {

    /**
     * 上传文件接口
     */
    @PostMapping(value = "/file/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    R<FileUploadVO> upload(@RequestPart("file") MultipartFile file, @RequestPart("bucketName") String bucketName, @RequestPart("endpoint") String endpoint);

    /**
     * 通过完整文件名, 删除服务器上的文件
     */
    @PostMapping("/file/delete")
    R<FileDeleteVO> delete(@RequestParam("wholeFileName") String wholeFileName);

    /**
     * 通过完整文件名, 获取远程地址
     */
    @GetMapping("/file/getRemoteUrl")
    R<String> getRemoteUrl(@RequestParam("wholeFileName") String wholeFileName);
}
